#include <iostream>
#include <string>
using namespace std;

class Solution
{
public:
    string Itos(int n)
    {
        string s;
        s.push_back(n % 10 + '0');
        while (n /= 10)
        {
            s.push_back(n % 10 + '0');
        }
        return { s.rbegin(),s.rend() };
    }

    string compressString(string S) 
    {
        if (S.empty())
            return { "" };
        
        int cnt = 1;
        string skt;
        for (int i = 1; i < S.size(); i++)
        {
            if (S[i] == S[i - 1])
            {
                cnt++;
            }
            else
            {
                skt.push_back(S[i - 1]);
                //skt += Itos(cnt);
                skt += to_string(cnt);

                cnt = 1;
            }
        }
        skt.push_back(S.back());
        //skt += Itos(cnt);
        skt += to_string(cnt);

        if (skt.size() >= S.size())
        {
            return S;
        }
        return skt;
    }
};


int main()
{
    //string s1{ "aabcccccaa" };
    string s1{ "aabccccca" };


    Solution xz;
    string s = xz.compressString(s1);
    cout << s << endl;

    /*Solution xz;
    string s = xz.Itos(123);
    cout << s << endl;*/

	return 0;
}
